import java.io.*;
import java.util.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;

public class InstructionGen
{
	public static void main(String [] args) throws SQLException
	{
		DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@146.187.134.17:1542:oracle10g", "cscd494", "R3tral435");
	 // @machineName:port:SID,   userid,  password
	
		Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
		ResultSet rset = stmt.executeQuery("select * FROM president");//later read from appropriate spot
		
		try
		{
			Scanner inFile = new Scanner(new File("exam_instruction.rtf"));//later read from DB
			PrintWriter outFile = new PrintWriter(new File("exam_instructions.rtf"));
			
			while(inFile.hasNext())
			{
				String s = inFile.nextLine();
				if(s.contains("InstructionsHere"))
				{
					int x = 1;
					while(rset.next())
					{
						//here is mixture of rtf style and java style...
						//need to drill more to get perfect result
						//http://www.biblioscape.com/rtf15_spec.htm
						outFile.println("{\\tab\\bullet}");
						outFile.println("Part " + x + ": ");
						outFile.println(rset.getString(2));//later...read something more useful...hopefully...
						outFile.println("{\\par}");
						x++;
					}
				}
				else
				{
					s = s.replace("DateHere", "Spring2009");//change any sequence of DateHere to exam date
					outFile.println(s);
				}
			}
			
			stmt.close();
			inFile.close();
			outFile.close();
		}
		catch(Exception e){ System.out.println(e); }
	}
		 
}
